using FSM.IDal; 
using FSM.IBll; 
using FSM.Model; 
using SqlSugar; 
using System; 
using System.Collections.Generic; 
using System.Text;
using Microsoft.Extensions.Logging;

namespace FSM.Bll 
{ 
    public class SysActionBll: ISysActionBll 
    { 
        #region 模块 
        private readonly ISysActionDal dal;
        private readonly ILogger<SysActionBll> _logger;
        public SysActionBll(ISysActionDal dal, ILogger<SysActionBll> logger) 
        { 
            this.dal = dal;
            this._logger = logger;
            this._logger.LogDebug("SysActionBll创建了");
        } 
        #endregion 
 
        #region 查询 
 
        /// <summary> 
        /// 根据键值查询单个信息 
        /// </summary> 
        /// <param name="act_no">键值</param> 
        /// <returns></returns> 
        public sys_action Get(string act_no) 
        { 
            return dal.GetById(act_no); 
        } 
 
        /// <summary> 
        /// 查询批量信息 
        /// </summary> 
        /// <param name="act_no">动作编号</param> 
        /// <param name="act_name">动作名称</param> 
        /// <param name="page">页码</param> 
        /// <param name="page_size">每页显示的条数</param> 
        /// <returns></returns> 
        public Tuple<List<sys_action>, int> List(string act_no, string act_name, int page, int page_size) 
        { 
            ISugarQueryable<sys_action> queryable = dal.CreateQueryable(); 
            queryable = queryable.WhereIF(!string.IsNullOrEmpty(act_no),p => p.act_no == act_no); 
            queryable = queryable.WhereIF(!string.IsNullOrEmpty(act_name),p => p.act_name == act_name);
            queryable = queryable.OrderBy(p => p.orderby);
             
            PageModel pm = new PageModel 
            { 
                PageIndex = page, 
                PageSize = page_size 
            }; 
            Tuple<List<sys_action>, int> result = dal.GetPageListAndTotal(queryable, pm); 
            return result; 
        } 
 
        #endregion 
 
        #region 提交 
 
        /// <summary> 
        /// 添加 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        public bool Insert(sys_action model) 
        { 
            model.create_date = DateTime.Now; 
            return dal.Insert(model); 
        } 
 
        /// <summary> 
        /// 更新 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        public bool Update(sys_action model) 
        { 
            model.edit_date = DateTime.Now; 
            return dal.UpdateExcludeColumns(model, "creater", "create_date") == 1; 
        } 
 
        /// <summary> 
        ///  删除 
        /// </summary> 
        /// <param name="act_no">键值</param> 
        /// <returns></returns> 
        public bool Delete(params string[] act_no_arr) 
        { 
            return dal.Delete(act_no_arr); 
        } 
        #endregion 
    } 
} 
